﻿using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

namespace GlimpseWcf.Core
{
    public class CookieCollectionDto
    {
        public struct CookieDto
        {
            public string Key;
            public string CookieValue;
        }

        public CookieCollectionDto(){ }

        [XmlArray]
        [XmlArrayItem(ElementName = "Cookie")]
        public List<CookieDto> Cookies;

        public CookieCollectionDto(List<CookieDto> cookies)
        {
            Cookies = cookies;
        }

        public CookieCollectionDto(HttpCookieCollection cookies)
        {
            Cookies = cookies.AllKeys.Where(k => cookies[k] != null).Select(c => new CookieDto{Key = c, CookieValue = cookies[c].Value}).ToList();
        }

        public Dictionary<string, string> GetDictionary()
        {
            return Cookies.ToDictionary(key => key.Key, value => value.CookieValue);
        }
    }

}
